<template>
  <div :class="['goods-list', !isRow && 'two']" v-if="list.length">
    <p class="row-control">
      <van-icon
        :class="!isRow && 'red'"
        @click="isRow = !isRow"
        :name="isRow ? 'qr-invalid' : 'qr'"
      />
    </p>
    <div v-for="item in list" :key="item.g_id" class="item">
      <nuxt-link :to="item.g_id | goodsUrl" class="img">
        <img :src="item.g_src | formatSrc" :alt="item.g_name" />
      </nuxt-link>
      <div class="info">
        <nuxt-link :to="item.g_id | goodsUrl" class="title text-over2">
          {{ item.g_name }}
        </nuxt-link>
        <div class="bottom">
          <div class="price red">
            <small>￥</small>
            {{ item.price }}
            <em> 已有{{ item.specs | getBuyNum }}人购买 </em>
          </div>
          <nuxt-link :to="item.b_id | storeUrl" class="store">
            {{ item.b_name }}
          </nuxt-link>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data: () => ({
    isRow: true
  }),
  props: {
    list: {
      type: Array,
      default: () => []
    }
  }
};
</script>
<style lang="scss" scoped>
.goods-list {
  padding: 10px;
  &.two {
    .item {
      &:nth-of-type(2n + 1) {
        margin-right: 4%;
      }
      width: 48%;
      display: inline-block;
      border-bottom: 0;
      .img {
        margin: 0;
      }
      img {
        width: 100%;
      }
    }
  }
  .red {
    color: red;
  }
  .row-control {
    display: flex;
    font-size: 16px;
    justify-content: flex-end;
    margin:0 0 15px;
    ::v-deep .van-icon {
      position: static;
    }
  }
  .item {
    margin-bottom: 10px;
    padding-bottom: 10px;
    display: flex;
    font-size: 14px;
    border-bottom: 1px solid #e9e9e9;
    color: #000;
  }
  .info {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }
  .store {
    padding-left: 1em;
    font-size: 12px;
    color: #a0a0a0;
  }
  .price {
    padding-top: 2px;
    font-size: 16px;
    font-weight: bold;
    small {
      font-weight: normal;
      font-size: 12px;
    }
    em {
      font-style: normal;
      font-weight: normal;
      font-size: 12px;
      color: #c3bfbf;
    }
  }
  .title {
    height: 3em;
    line-height: 1.5;
    color: #000;
  }
  .img {
    margin-right: 10px;
  }
  img {
    display: block;
    width: 100px;
    height: auto;
  }
}
</style>
